<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html>
<head>
    <!-- 包含公共的JSP代码片段 -->

    <title>无线点餐平台</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <script type="text/javascript" src="${pageContext.request.contextPath}/detail/style/js/jquery.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/detail/style/js/page_common.js"></script>
    <link href="${pageContext.request.contextPath}/detail/style/css/common_style_blue.css" rel="stylesheet" type="text/css">
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/detail/style/css/index_1.css" />
</head>
<body>
<!-- 页面标题 -->
<div id="TitleArea">
    <div id="TitleArea_Head"></div>
    <div id="TitleArea_Title">
        <div id="TitleArea_Title_Content">
            <img border="0" width="13" height="13" src="${pageContext.request.contextPath}/detail/style/images/title_arrow.gif"/> 商品列表
        </div>
    </div>
    <div id="TitleArea_End"></div>
</div>


<!-- 过滤条件 -->
<div id="QueryArea">
    <input type="hidden" name="method" value="search">
    <input type="text" name="keyword" title="请输入菜品名称">
    <input type="button" class="fuzzyquery" value="搜索">
</div>
<!-- 主内容区域（数据列表或表单显示） -->
<div id="MainArea">
    <table class="MainArea_Content" align="center" cellspacing="0" cellpadding="0">
        <!-- 表头-->
        <thead>
        <tr align="center" valign="middle" id="TableTitle">
            <td>商品编号</td>
            <td>商品名称</td>
            <td>所属类型</td>
            <td>商品价格</td>
            <td>操作</td>
        </tr>
        </thead>
        <!--显示数据列表 -->
        <tbody id="TableData" class="datas">

        </tbody>
    </table>

    <!-- 其他功能超链接 -->
    <div id="TableTail" align="center">
    </div>
</div>
</body>
<script type="text/javascript">
    //定义方法发送ajax向后台发送数据
    $(function () {
       getDatas("","");
        //模糊查询
        $(".fuzzyquery").bind("click",function () {
            var condition = $("input[name=keyword]").val();
            var pageNO = 1;
            getDatas(pageNO,condition);
        });
        //首页
        $("#homepage").live("click", function() {
            var condition = $("input[name=keyword]").val();
            var pageNO = 1;
            getDatas(pageNO,condition);
        });
        //下一页
        $("#nextpage").live("click", function() {
            var condition = $("input[name=keyword]").val();
            var pageNO = $(".pageNO").text();
            pageNO = parseInt(pageNO);
            var pageSize = $(".pageSize").text();
            pageSize = parseInt(pageSize);
            if (pageNO==undefined){
                pageNO=1;
            }else if (pageNO>=pageSize){
                pageNO=pageSize;
            }else {
                pageNO = pageNO+1;
            }
            getDatas(pageNO,condition);
        });
        //上一页
        $("#previouspage").live("click",function () {
            var condition = $("input[name=keyword]").val();
            var pageNO = $(".pageNO").text();
            pageNO = parseInt(pageNO);
            if (pageNO==undefined || pageNO<=1){
                pageNO=1;
            }else {
                pageNO = pageNO-1;
            }
            getDatas(pageNO,condition);
        });
        //尾页
        $("#trailerpage").live("click",function () {
            var condition = $("input[name=keyword]").val();
            var pageSize = $(".pageSize").text();
            pageSize = parseInt(pageSize);
            if (pageSize==undefined){
                pageSize=1;
            }
            getDatas(pageSize,condition);
        });
       function getDatas(pageNO,condition) {
           $(".datas").empty();
           $("#TableTail").empty();
           $.ajax({
               url:"../query_Dessert_All.action",
               data:{"pageNO":pageNO,"condition":condition},
               type:"post",
               dataType:"json",
               success:function (data) {
                   console.log(data);
                   if (data.success){
                        var dessert = data.data.list;
                        for (var i=0;i<dessert.length;i++){
                            var de = dessert[i];
                            $(".datas").append("<tr class='TableDetail1'><td>"+de.dessertEntity.dessertId+"</td><td>"+de.dessertEntity.dessertName+"</td><td>"+de.desserttypeEntity.typeName+"</td><td>"+de.dessertEntity.dessertPrice+"</td><td><a href='../detail/saveFood.jsp' class='FunctionButton'>添加</a><a href='../query_Dessert_DessertId.action?dessertId="+de.dessertEntity.dessertId+"' class='FunctionButton'>更新</a><a href='../delete_Dessert.action?dessertId="+de.dessertEntity.dessertId+"' class='FunctionButton'>删除</a></td></tr>");
                        }
                       $("#TableTail").append("<tr><td align='center'><span>共"+data.data.totalRecords+"条数据</span>&emsp;<span class='pageSize'>"+data.data.totalPages+"</span>/<span class='pageNO'>"+data.data.pageNo+"</span>&emsp;&emsp;&emsp;<a href='javascript:void(0);' id='homepage' class='FunctionButton'>首页</a>&emsp;<a href='javascript:void(0);' id='nextpage' class='FunctionButton'>下一页</a>&emsp;<a href='javascript:void(0);' id='previouspage' class='FunctionButton'>上一页</a>&emsp;<a href='javascript:void(0);' id='trailerpage' class='FunctionButton'>尾页</a></td></tr>");
                   }
                   else {
                       $(".datas").append("<tr class='TableDetail1'><td>还没有数据哦...</td></tr>");
                   }
               }
           });
       }
    });
</script>
</html>
